import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import loginInfo from './loginInfo';

export default function ProtectedRoute({component: Component, children, render, ...rest}) {
    console.log(rest)
    return <Route {...rest} render={values => {
        if (loginInfo.isLogin) {
            return <Component /> 
        } else {
            // return <Redirect to={{
            //     pathname: "/login",
            //     search: "?returnUrl=" + values.location.pathname
            // }} />

            return <Redirect to={{
                pathname: "/login",
                state: values.location.pathname
            }} />
        }
    }} />
}
